﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_Flow_BackManage_UpdateNewFlow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 53)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            this.RangeValidator1.MaximumValue = Int32.MaxValue.ToString();
            Flow_NewFlow fnf = Flow_NewFlow_Service.FindByFlowId(Convert.ToInt32(Request.QueryString["id"]));
            ddlBase_Flow.SelectedValue = fnf.Base_flow.Id.ToString();
            ddl_Form.SelectedValue = fnf.Flow_Form.Id.ToString();
            ddlAllow_AffixFile.SelectedValue = fnf.Allow_affixFile.ToString();
            ddlNew_Flow_Type.SelectedValue = fnf.NewFlow_type.ToString();
            txtNew_Flow_Name.Text = fnf.NewFlow_name;
            txtNew_Flow_Sort.Text = fnf.NewFlow_sort.ToString();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Flow_NewFlow fnf = new Flow_NewFlow();
        Flow_Forms ff = new Flow_Forms();
        ff.Id = Convert.ToInt32(ddl_Form.SelectedValue);
        fnf.Flow_Form = ff;
        fnf.NewFlow_sort = Convert.ToInt32(txtNew_Flow_Sort.Text.Trim());
        fnf.NewFlow_name = txtNew_Flow_Name.Text.Trim();
        fnf.NewFlow_type = Convert.ToInt32(ddlNew_Flow_Type.SelectedValue);
        Flow_Type ft = new Flow_Type();
        ft.Id = Convert.ToInt32(ddlBase_Flow.SelectedValue);
        fnf.Base_flow = ft;
        fnf.Allow_affixFile = Convert.ToInt32(ddlAllow_AffixFile.SelectedValue);
        fnf.NewFlowl_id = Convert.ToInt32(Request.QueryString["id"]);
        if (Flow_NewFlow_Service.UpdateNewFlow(fnf))
        {
            Response.Redirect("Flow_NewFlowList.aspx");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改失败！请重试！')", true);
        }
    }
}
